<?php
/**
 * Created by PhpStorm.
 * User: ciwei
 * Date: 2017/12/5
 * Time: 15:37
 */
namespace app\index\controller;

use think\Controller;
use think\Request;

class Common extends Controller
{
    public function _initialize()
    {
        $request = Request::instance();
        $path = $request->module().'/'.$request->controller().'/'.$request->action();
        $path = strtolower($path);

        $this->check($path);
    }
    public function check($path)
    {
        if (!session('uid')){
            $auth = config('auth');
            foreach ($auth as $k => $v){
                if ($v == $path){
                    $request = Request::instance();
                    if($request->isAjax()){
                        exit(json_encode(['error'=>1,'info'=>'请先登录']));
                    }else{
                        $this->error('请先登录',url('index/log/login'),1);
                    }

                }
            }

        }

    }
}
